#include "calculatingexpression.h"
#include "testkeycall.h"
int CallAllTest()
{
    TestConvertToPostfix_CaseTrue01();
    TestConvertToPostfix_CaseTrue02();
    TestConvertToPostfix_CaseTrue03();
    TestConvertToPostfix_CaseTrue04();
    TestConvertToPostfix_CaseTrue05();
    TestConvertToPostfix_CaseTrue06();
    TestConvertToPostfix_CaseTrue07();
    TestConvertToPostfix_CaseTrue08();
    TestConvertToPostfix_CaseTrue09();
    TestConvertToPostfix_CaseTrue10();
}

int CompareExpectedAndActually(char expected[30][50], char actually[30][50])
{
    //Compare actually with expected
    //if number of item is not the same, return 0
    //if(expected != actually) return 0;
    int i,j;
    for (i=0; actually[i][0]!='\0'; i++)
    {
        for (j=0; actually[i][j]!='\0'; j++)
        {
            if (actually[i][j] != expected[i][j])
            {
                return 0;
            }
        }
        if (expected[i][j+1] !='\0')
        {
            return 0;
        }
    }
    if (expected[i+1][0] !='\0')
    {
        return 0;
    }
    //if any item is not the same, return 0

    return 1;
}
int TestConvertToPostfix_CaseTrue01()
{
    char exp[30][50];
    exp[0][0] = '3';
    exp[1][0] = '+';
    exp[2][0] = '4';

    char expected[30][50];
    exp[0][0] = '3';
    exp[1][0] = '4';
    exp[2][0] = '+';

    char actually[30][50];

    ConvertToPostfix(exp, actually);

    if(CompareExpectedAndActually(exp, actually))
    {
        printf(" - Test key 1: true!\n", actually);
        return 1;
    }
    else
    {
        printf(" - Test key 1: false!\n");
        return 0;
    }
}
int TestConvertToPostfix_CaseTrue02()
{
    char exp[30][50];
    exp[0][0] = '3';
    exp[1][0] = '+';
    exp[2][0] = '4';
    exp[3][0] = '/';
    exp[4][0] = '5';

    char expected[30][50];
    exp[0][0] = '3';
    exp[1][0] = '4';
    exp[2][0] = '5';
    exp[3][0] = '/';
    exp[4][0] = '+';

    char actually[30][50];

    ConvertToPostfix(exp, actually);

    if(CompareExpectedAndActually(exp, actually))
    {
        printf(" - Test key 2: true!\n");
        return 1;
    }
    else
    {
        printf(" - Test key 2: false!\n");
        return 0;
    }
}
int TestConvertToPostfix_CaseTrue03()
{
    char exp[30][50];
    exp[0][0] = '3';
    exp[1][0] = '+';
    exp[2][0] = '4';
    exp[3][0] = '/';
    exp[4][0] = '5';
    exp[5][0] = '/';
    exp[6][0] = '6';
    exp[7][0] = '*';
    exp[8][0] = '7';

    char expected[30][50];
    exp[0][0] = '3';
    exp[1][0] = '4';
    exp[2][0] = '5';
    exp[3][0] = '/';
    exp[4][0] = '6';
    exp[5][0] = '/';
    exp[6][0] = '7';
    exp[7][0] = '*';
    exp[8][0] = '+';

    char actually[30][50];

    ConvertToPostfix(exp, actually);

    if(CompareExpectedAndActually(exp, actually))
    {
        printf(" - Test key 3: true!\n");
        return 1;
    }
    else
    {
        printf(" - Test key 3: false!\n");
        return 0;
    }
}
int TestConvertToPostfix_CaseTrue04()
{
    char exp[30][50];
    exp[0][0] = '3';
    exp[1][0] = '+';
    exp[2][0] = '4';
    exp[3][0] = '/';
    exp[4][0] = '5';
    exp[5][0] = '/';
    exp[6][0] = '6';
    exp[7][0] = '*';
    exp[8][0] = '7';
    exp[9][0] = '-';
    exp[10][0] = '8';
    exp[10][1] = '7';

    char expected[30][50];
    exp[0][0] = '3';
    exp[1][0] = '4';
    exp[2][0] = '5';
    exp[3][0] = '/';
    exp[4][0] = '6';
    exp[5][0] = '/';
    exp[6][0] = '7';
    exp[7][0] = '*';
    exp[8][0] = '+';
    exp[9][0] = '8';
    exp[9][1] = '7';
    exp[10][0] = '-';

    char actually[30][50];

    ConvertToPostfix(exp, actually);

    if(CompareExpectedAndActually(exp, actually))
    {
        printf(" - Test key 4: true!\n");
        return 1;
    }
    else
    {
        printf(" - Test key 4: false!\n");
        return 0;
    }
}
int TestConvertToPostfix_CaseTrue05()
{
    char exp[30][50];
    exp[0][0] = '3';


    char expected[30][50];
    exp[0][0] = '3';


    char actually[30][50];

    ConvertToPostfix(exp, actually);

    if(CompareExpectedAndActually(exp, actually))
    {
        printf(" - Test key 5: true!\n");
        return 1;
    }
    else
    {
        printf(" - Test key 5: false!\n");
        return 0;
    }
}
int TestConvertToPostfix_CaseTrue06()
{
    char exp[30][50];
    exp[0][0] = '-';
    exp[1][0] = '3';


    char expected[30][50];
    exp[0][0] = '3';
    exp[1][0] = '-';

    char actually[30][50];

    ConvertToPostfix(exp, actually);

    if(CompareExpectedAndActually(exp, actually))
    {
        printf(" - Test key 6: true!\n");
        return 1;
    }
    else
    {
        printf(" - Test key 6: false!\n");
        return 0;
    }
}
int TestConvertToPostfix_CaseTrue07()
{
    char exp[30][50];
    exp[0][0] = '2';
    exp[0][1] = '.';
    exp[0][2] = '5';
    exp[0][3] = '6';
    exp[1][0] = '+';
    exp[2][0] = '5';
    exp[3][0] = '-';
    exp[4][0] = '6';
    exp[4][1] = '7';

    char expected[30][50];
    exp[0][0] = '2';
    exp[0][1] = '.';
    exp[0][2] = '5';
    exp[0][3] = '6';
    exp[1][0] = '5';
    exp[2][0] = '+';
    exp[3][0] = '6';
    exp[3][1] = '7';
    exp[4][0] = '-';

    char actually[30][50];

    ConvertToPostfix(exp, actually);

    if(CompareExpectedAndActually(exp, actually))
    {
        printf(" - Test key 7: true!\n");
        return 1;
    }
    else
    {
        printf(" - Test key 7: false!\n");
        return 0;
    }
}
int TestConvertToPostfix_CaseTrue08()
{
    char exp[30][50];
    exp[0][0] = '3';
    exp[1][0] = '*';
    exp[2][0] = '(';
    exp[3][0] = '4';
    exp[4][0] = '+';
    exp[5][0] = '5';
    exp[6][0] = ')';
    exp[7][0] = '-';
    exp[8][0] = '6';

    char expected[30][50];
    exp[0][0] = '3';
    exp[1][0] = '4';
    exp[2][0] = '5';
    exp[3][0] = '+';
    exp[4][0] = '*';
    exp[5][0] = '6';
    exp[6][0] = '-';


    char actually[30][50];

    ConvertToPostfix(exp, actually);

    if(CompareExpectedAndActually(exp, actually))
    {
        printf(" - Test key 8: true!\n");
        return 1;
    }
    else
    {
        printf(" - Test key 8: false!\n");
        return 0;
    }
}
int TestConvertToPostfix_CaseTrue09()
{
    char exp[30][50];
    exp[0][0] = '3';
    exp[1][0] = '*';
    exp[2][0] = '(';
    exp[3][0] = '4';
    exp[4][0] = '/';
    exp[5][0] = '(';
    exp[6][0] = '5';
    exp[7][0] = '-';
    exp[8][0] = '6';
    exp[9][0] = ')';
    exp[10][0] = ')';

    char expected[30][50];
    exp[0][0] = '3';
    exp[1][0] = '4';
    exp[2][0] = '5';
    exp[3][0] = '6';
    exp[4][0] = '-';
    exp[5][0] = '/';
    exp[6][0] = '*';


    char actually[30][50];

    ConvertToPostfix(exp, actually);

    if(CompareExpectedAndActually(exp, actually))
    {
        printf(" - Test key 9: true!\n");
        return 1;
    }
    else
    {
        printf(" - Test key 9: false!\n");
        return 0;
    }
}
int TestConvertToPostfix_CaseTrue10()
{
    char exp[30][50];
    exp[0][0] = '3';
    exp[1][0] = '*';
    exp[2][0] = '(';
    exp[3][0] = '(';
    exp[4][0] = '4';
    exp[5][0] = '-';
    exp[6][0] = '5';
    exp[7][0] = ')';
    exp[8][0] = '/';
    exp[9][0] = '(';
    exp[10][0] = '6';
    exp[11][0] = '+';
    exp[12][0] = '7';
    exp[13][0] = ')';
    exp[14][0] = ')';

    char expected[30][50];
    exp[0][0] = '3';
    exp[1][0] = '4';
    exp[2][0] = '5';
    exp[3][0] = '-';
    exp[4][0] = '6';
    exp[5][0] = '7';
    exp[6][0] = '+';
    exp[6][0] = '/';
    exp[6][0] = '*';

    char actually[30][50];

    ConvertToPostfix(exp, actually);

    if(CompareExpectedAndActually(exp, actually))
    {
        printf(" - Test key 10: true!\n");
        return 1;
    }
    else
    {
        printf(" - Test key 10: false!\n");
        return 0;
    }
}

